1
|
|
|
Nitrate.TestCases = {}; |
|
|
|
|
2
|
|
|
Nitrate.TestCases.Edit = {}; |
3
|
|
|
Nitrate.TestCases.Clone = {}; |
4
|
|
|
|
5
|
|
|
(function() { |
6
|
|
|
var TestCases = window.Nitrate.TestCases || {}; |
7
|
|
|
|
8
|
|
|
TestCases.CasesSelection = function(options) { |
9
|
|
|
this.selectedCasesIds = options.selectedCasesIds || []; |
10
|
|
|
this.selectAll = options.selectAll; |
11
|
|
|
|
12
|
|
|
if (Object.prototype.toString.call(this.selectedCasesIds) !== '[object Array]') { |
13
|
|
|
throw new TypeError('selectedCasesIds must an object of Array.'); |
14
|
|
|
} |
15
|
|
|
if (typeof this.selectAll !== 'boolean') { |
16
|
|
|
throw new TypeError('selectAll must be a boolean value.'); |
17
|
|
|
} |
18
|
|
|
}; |
19
|
|
|
|
20
|
|
|
TestCases.CasesSelection.prototype.empty = function() { |
21
|
|
|
return this.selectedCasesIds.length === 0 && !this.selectAll; |
22
|
|
|
}; |
23
|
|
|
|
24
|
|
|
window.Nitrate.TestCases = TestCases; |
25
|
|
|
}()); |
26
|
|
|
|
27
|
|
|
function configure_product_on_load() { |
28
|
|
|
$('#id_product').change(function() { |
29
|
|
|
$('#id_category').find('option').remove(); |
30
|
|
|
update_category_select_from_product(); |
31
|
|
|
}); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
Nitrate.TestCases.Edit.on_load = function() { |
35
|
|
|
configure_product_on_load(); |
36
|
|
|
if ($('#id_category').val() === null || !$('#id_category').val().length) { |
37
|
|
|
update_category_select_from_product(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
jQ('.js-back-button').bind('click', function() { |
41
|
|
|
window.history.go(-1); |
42
|
|
|
}); |
43
|
|
|
}; |
44
|
|
|
|
45
|
|
|
Nitrate.TestCases.Clone.on_load = function() { |
46
|
|
|
$('#id_product').change(update_version_select_from_product); |
|
|
|
|
47
|
|
|
if (!$('#id_version').val().length) { |
48
|
|
|
update_version_select_from_product(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
jQ('#id_form_search_plan').bind('submit', function(e) { |
52
|
|
|
e.stopPropagation(); |
53
|
|
|
e.preventDefault(); |
54
|
|
|
|
55
|
|
|
var url = '/plans/'; |
56
|
|
|
var container = jQ('#id_plan_container'); |
57
|
|
|
container.show(); |
58
|
|
|
|
59
|
|
|
jQ.ajax({ |
|
|
|
|
60
|
|
|
'url': url, |
61
|
|
|
'type': 'GET', |
62
|
|
|
'data': jQ(this).serialize(), |
63
|
|
|
'success': function (data, textStatus, jqXHR) { |
|
|
|
|
64
|
|
|
container.html(data); |
65
|
|
|
} |
66
|
|
|
}); |
67
|
|
|
}); |
68
|
|
|
|
69
|
|
|
jQ('#id_use_filterplan').bind('click', function(e) { |
|
|
|
|
70
|
|
|
jQ('#id_form_search_plan :input').attr('disabled', false); |
71
|
|
|
jQ('#id_plan_id').val(''); |
72
|
|
|
jQ('#id_plan_id').attr('name', ''); |
73
|
|
|
jQ('#id_copy_case').attr('checked', true); |
74
|
|
|
}); |
75
|
|
|
|
76
|
|
|
if (jQ('#id_use_sameplan').length) { |
77
|
|
|
jQ('#id_use_sameplan').bind('click', function(e) { |
|
|
|
|
78
|
|
|
jQ('#id_form_search_plan :input').attr('disabled', true); |
79
|
|
|
jQ('#id_plan_id').val(jQ('#value_plan_id').val()); |
80
|
|
|
jQ('#id_plan_id').attr('name', 'plan'); |
81
|
|
|
jQ('#id_plan_container').html('<div class="ajax_loading"></div>').hide(); |
82
|
|
|
jQ('#id_copy_case').attr('checked', false); |
83
|
|
|
}); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
jQ('.js-cancel-button').bind('click', function() { |
87
|
|
|
window.history.go('-1'); |
88
|
|
|
}); |
89
|
|
|
|
90
|
|
|
}; |
91
|
|
|
|
92
|
|
|
|
93
|
|
|
/* |
94
|
|
|
* Used for expanding test case in test plan page specifically |
95
|
|
|
* |
96
|
|
|
* Arguments: |
97
|
|
|
* options.caseRowContainer: a jQuery object referring to the container of the |
98
|
|
|
* test case that is being expanded to show more |
99
|
|
|
* information. |
100
|
|
|
* options.expandPaneContainer: a jQuery object referring to the container of |
101
|
|
|
* the expanded pane showing test case detail |
102
|
|
|
* information. |
103
|
|
|
*/ |
104
|
|
|
function toggleExpandArrow(options) { |
105
|
|
|
var container = options.caseRowContainer; |
106
|
|
|
var content_container = options.expandPaneContainer; |
107
|
|
|
var blind_icon = container.find('img.blind_icon'); |
108
|
|
|
if (content_container.css('display') === 'none') { |
109
|
|
|
blind_icon.removeClass('collapse').addClass('expand').attr('src', '/static/images/t1.gif'); |
110
|
|
|
} else { |
111
|
|
|
blind_icon.removeClass('expand').addClass('collapse').attr('src', '/static/images/t2.gif'); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
|
116
|
|
|
function toggleTestCaseContents(template_type, container, content_container, object_pk, case_text_version, case_run_id, callback) { |
117
|
|
|
if (typeof container === 'string') { |
118
|
|
|
var container = jQ('#' + container)[0]; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
if(typeof content_container === 'string') { |
122
|
|
|
var content_container = jQ('#' + content_container)[0]; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
jQ(content_container).toggle(); |
126
|
|
|
|
127
|
|
|
if (jQ('#id_loading_' + object_pk).length) { |
128
|
|
|
var url = Nitrate.http.URLConf.reverse({ name: 'case_details', arguments: {id: object_pk} }); |
|
|
|
|
129
|
|
|
var parameters = { |
130
|
|
|
template_type: template_type, |
131
|
|
|
case_text_version: case_text_version, |
132
|
|
|
case_run_id: case_run_id |
133
|
|
|
}; |
134
|
|
|
|
135
|
|
|
jQ.ajax({ |
|
|
|
|
136
|
|
|
'url': url, |
137
|
|
|
'data': parameters, |
138
|
|
|
'success': function (data, textStatus, jqXHR) { |
|
|
|
|
139
|
|
|
jQ(content_container).html(data); |
140
|
|
|
}, |
141
|
|
|
'error': function (jqXHR, textStatus, errorThrown) { |
|
|
|
|
142
|
|
|
html_failure(); |
143
|
|
|
}, |
144
|
|
|
'complete': function (jqXHR, textStatus) { |
|
|
|
|
145
|
|
|
callback(jqXHR); |
146
|
|
|
} |
147
|
|
|
}); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
toggleExpandArrow({ caseRowContainer: jQ(container), expandPaneContainer: jQ(content_container) }); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
function changeTestCaseStatus(plan_id, case_ids, new_value, container) { |
154
|
|
|
case_ids.forEach(function(element) { |
155
|
|
|
jsonRPC('TestCase.update', [element, {case_status: new_value}], function(data) {}); |
|
|
|
|
156
|
|
|
}); |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
var template_type = 'case'; |
160
|
|
|
if (container.attr('id') === 'reviewcases') { |
161
|
|
|
template_type = 'review_case'; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
var parameters = { |
165
|
|
|
'a': 'initial', |
166
|
|
|
'from_plan': plan_id, |
167
|
|
|
'template_type': template_type, |
168
|
|
|
}; |
169
|
|
|
|
170
|
|
|
// todo: #run_case_count, #case_count, #review_case_count |
171
|
|
|
// are no longer updated |
172
|
|
|
constructPlanDetailsCasesZone(container, plan_id, parameters); |
173
|
|
|
|
174
|
|
|
Nitrate.TestPlans.Details.reopenTabHelper(jQ(container)); |
|
|
|
|
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
function toggleAllCheckBoxes(element, container, name) { |
178
|
|
|
if (element.checked) { |
179
|
|
|
jQ('#' + container).parent().find('input[name="' + name + '"]').not(':disabled').attr('checked', true); |
180
|
|
|
} else { |
181
|
|
|
jQ('#' + container).parent().find('input[name="'+ name + '"]').not(':disabled').attr('checked', false); |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
function toggleAllCases(element) { |
186
|
|
|
//If and only if both case length is 0, remove the lock. |
187
|
|
|
if (jQ('div[id^="id_loading_"].normal_cases').length === 0 && jQ('div[id^="id_loading_"].review_cases').length === 0){ |
188
|
|
|
jQ(element).removeClass('locked'); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
if (jQ(element).is('.locked')) { |
192
|
|
|
return false; |
193
|
|
|
} else { |
|
|
|
|
194
|
|
|
jQ(element).addClass('locked'); |
195
|
|
|
if (jQ(element).is('.collapse-all')) { |
196
|
|
|
element.title = "Collapse all cases"; |
197
|
|
|
blinddownAllCases(element); |
|
|
|
|
198
|
|
|
} else { |
199
|
|
|
element.title = "Expand all cases"; |
200
|
|
|
blindupAllCases(element); |
|
|
|
|
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
function blinddownAllCases(element) { |
206
|
|
|
jQ('img.expand').each(function(e) { |
|
|
|
|
207
|
|
|
fireEvent(this, 'click'); |
208
|
|
|
}); |
209
|
|
|
if (element) { |
210
|
|
|
jQ(element) |
211
|
|
|
.removeClass('collapse-all').addClass('expand-all') |
212
|
|
|
.attr('src', '/static/images/t2.gif'); |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
function blindupAllCases(element) { |
217
|
|
|
jQ('.collapse').each(function(e) { |
|
|
|
|
218
|
|
|
fireEvent(this, 'click'); |
219
|
|
|
}); |
220
|
|
|
|
221
|
|
|
if (element) { |
222
|
|
|
jQ(element) |
223
|
|
|
.removeClass('expand-all').addClass('collapse-all') |
224
|
|
|
.attr('src', '/static/images/t1.gif'); |
225
|
|
|
} |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/* |
229
|
|
|
* Serialize selected cases' Ids. |
230
|
|
|
* |
231
|
|
|
* This function inherits the ability from original definition named |
232
|
|
|
* serializeCaseFromInputList, except that it also collects whehter all cases |
233
|
|
|
* are also selected even through not all of cases are displayed. |
234
|
|
|
* |
235
|
|
|
* Return value is an object of dictionary holding two properties. `selectAll' |
236
|
|
|
* is a boolean value indicating whether user select all cases. |
237
|
|
|
* `selectedCasesIds' is an array containing all selected cases' Ids the |
238
|
|
|
* current loaded set of cases. |
239
|
|
|
* |
240
|
|
|
* Whatever user selects all cases, above two properties appears always with |
241
|
|
|
* proper value. |
242
|
|
|
*/ |
243
|
|
|
function serializeCaseFromInputList2(table) { |
244
|
|
|
var selectAll = jQ(table).parent().find('.js-cases-select-all input[type="checkbox"]')[0].checked; |
245
|
|
|
var case_ids = []; |
246
|
|
|
var checkedCases = jQ(table).find('input[name="case"]:checked'); |
247
|
|
|
checkedCases.each(function(i, checkedCase) { |
248
|
|
|
if (typeof checkedCase.value === 'string') { |
249
|
|
|
case_ids.push(checkedCase.value); |
250
|
|
|
} |
251
|
|
|
}); |
252
|
|
|
var selectedCasesIds = case_ids; |
253
|
|
|
|
254
|
|
|
return new Nitrate.TestCases.CasesSelection({ |
|
|
|
|
255
|
|
|
selectedCasesIds: selectedCasesIds, |
256
|
|
|
selectAll: selectAll |
257
|
|
|
}); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
function serializeCaseFromInputList(table) { |
261
|
|
|
var case_ids = []; |
262
|
|
|
jQ(table).parent().find('input[name="case"]:checked').each(function(i) { |
|
|
|
|
263
|
|
|
if (typeof this.value === 'string') { |
264
|
|
|
case_ids.push(this.value); |
265
|
|
|
} |
266
|
|
|
}); |
267
|
|
|
return case_ids; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/* |
271
|
|
|
* Serialize criterias for searching cases. |
272
|
|
|
* |
273
|
|
|
* Arguments: |
274
|
|
|
* - form: the form from which criterias are searched |
275
|
|
|
* - table: the table containing all loaded cases |
276
|
|
|
* - serialized: whether to serialize the form data. true is default, if not |
277
|
|
|
* passed. |
278
|
|
|
* - exclude_cases: whether to exclude all cases while serializing. For |
279
|
|
|
* instance, when filter cases, it's unnecessary to collect all selected |
280
|
|
|
* cases' IDs, due to all filtered cases in the response should be selected |
281
|
|
|
* by default. Default to true if not passed. |
282
|
|
|
*/ |
283
|
|
|
function serialzeCaseForm(form, table, serialized, exclude_cases) { |
|
|
|
|
284
|
|
|
if (typeof serialized != 'boolean') { |
285
|
|
|
var serialized = true; |
286
|
|
|
} |
287
|
|
|
if (exclude_cases === undefined) { |
288
|
|
|
var exclude_cases = false; |
289
|
|
|
} |
290
|
|
|
var data; |
291
|
|
|
if (serialized) { |
292
|
|
|
data = Nitrate.Utils.formSerialize(form); |
|
|
|
|
293
|
|
|
} else { |
294
|
|
|
data = jQ(form).serialize(); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
if (!exclude_cases) { |
298
|
|
|
data['case'] = serializeCaseFromInputList(table); |
299
|
|
|
} |
300
|
|
|
return data; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/* |
304
|
|
|
* New implementation of serialzeCaseForm to allow to choose whether the |
305
|
|
|
* TestCases' Ids are necessary to be serialized. |
306
|
|
|
* |
307
|
|
|
* Be default if no value is passed to exclude_cases, not exclude them. |
308
|
|
|
*/ |
309
|
|
|
function serializeCaseForm2(form, table, serialized, exclude_cases) { |
|
|
|
|
310
|
|
|
if (typeof serialized != 'boolean') { |
311
|
|
|
var serialized = true; |
312
|
|
|
} |
313
|
|
|
var data; |
314
|
|
|
if (serialized) { |
315
|
|
|
data = Nitrate.Utils.formSerialize(form); |
|
|
|
|
316
|
|
|
} else { |
317
|
|
|
data = jQ(form).serialize(); |
318
|
|
|
} |
319
|
|
|
var _exclude = exclude_cases === undefined ? false : exclude_cases; |
320
|
|
|
if (!_exclude) { |
321
|
|
|
data['case'] = serializeCaseFromInputList(table); |
322
|
|
|
} |
323
|
|
|
return data; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
function toggleDiv(link, divId) { |
327
|
|
|
var link = jQ(link); |
328
|
|
|
var div = jQ('#' + divId); |
329
|
|
|
var show = 'Show All'; |
330
|
|
|
var hide = 'Hide All'; |
331
|
|
|
div.toggle(); |
332
|
|
|
var text = link.html(); |
333
|
|
|
if (text !== show) { |
334
|
|
|
link.html(show); |
335
|
|
|
} else { |
336
|
|
|
link.html(hide); |
337
|
|
|
} |
338
|
|
|
} |
339
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.